/*
 *  UI_EQPanel.cpp
 *
 *	Date: 2011-8-8
 *  Author: linshenqi
 */

#include "stdafx.h"
#include "./UI_Frame.h"

extern CDC *g_pDC;
extern CDC g_MemDC;

UI_EQPanel::UI_EQPanel(const CRect *pRect, const GRAPHICPROP *pProp)
	: GraphicBase(pRect, pProp)
	, m_str("SPEQ")
	, m_ft(RGB(255, 255, 255))
	, m_nValue(0)
{
	m_lf.lfCharSet = DEFAULT_CHARSET;
	m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf.lfEscapement = 0;
	strcpy(m_lf.lfFaceName, FONT_CAPTION);
	m_lf.lfHeight = 16;
	m_lf.lfItalic = true;
	m_lf.lfOrientation = 0;
	m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf.lfPitchAndFamily = DEFAULT_PITCH;
	m_lf.lfQuality = DEFAULT_QUALITY;
	m_lf.lfStrikeOut = false;
	m_lf.lfUnderline = false;
	m_lf.lfWidth = 0;
	m_lf.lfWeight = 0;
}

void UI_EQPanel::SetRect(const CRect *pRect)
{
	GraphicBase::SetRect(pRect);
	CRect rc;
	int nw = (pRect->Width() - 7 * IP_PADDING) / 8;
	for(int i = 0; i < 8; ++i)
	{
		rc.SetRect(pRect->left + i * (nw + IP_PADDING), pRect->top, pRect->left + i * (nw + IP_PADDING) + nw, pRect->bottom);
		this->m_TB[i].SetRect(&rc);
		this->m_TB[i].SetBmp(BMP_MIX_EN, &rc);
		this->m_TB[i].SetColor(COLOR_FORE_MOUSEIN);
	}

	this->m_Line.Start.x = this->m_TB[0].m_pRect->right;
	this->m_Line.Start.y = this->m_TB[0].m_pRect->CenterPoint().y;
	this->m_Line.End.x = this->m_TB[7].m_pRect->right + IP_PADDING;
	this->m_Line.End.y = this->m_TB[0].m_pRect->CenterPoint().y;
}

void UI_EQPanel::SetID(int id)
{
	GraphicBase::SetID(id);
	for(int i = 0; i < 8; ++i)
	{
		this->m_TB[i].SetID(i);
	}
}

void UI_EQPanel::SetBaseWindow(CWnd *pWnd)
{
	GraphicBase::SetBaseWindow(pWnd);
	for(int i = 0; i < 8; ++i)
	{
		this->m_TB[i].SetBaseWindow(pWnd);
		this->m_TB[i].SetParent(this);
	}
}

bool UI_EQPanel::OnPaint(CPaintDC *pDC, CDC *pMemDC)
{
	GRAPHICPROP prop;
	prop.clrFill = COLOR_LINE;
	prop.clrFrame = COLOR_LINE;
	this->DrawLine(&this->m_Line.Start, &this->m_Line.End, &prop, pDC, pDC);

	CRect rc;
	rc.SetRect(this->m_Line.End.x + 16, 
				this->m_Line.End.y - 12, 
				this->m_Line.End.x + 24,
				this->m_Line.End.y - 4);
	this->DrawText(&m_lf, &rc, this->m_str, COLOR_FONT, pDC, pDC);

	for(int i = 0; i < FMB_NUM; ++i)
	{
		m_TB[i].OnPaint(pDC, pMemDC);
	}

	GraphicBase::OnPaint(pDC, pMemDC);
	return true;
}

bool UI_EQPanel::OnMouseMove(UINT nFlags, CPoint point)
{
	for(int i = 0; i < FMB_NUM; ++i)
	{
		m_TB[i].OnMouseMove(nFlags, point);
	}

	return GraphicBase::OnMouseMove(nFlags, point);
}

bool UI_EQPanel::OnLButtonDblClk(UINT nFlags, CPoint point)		
{
	CRect rc;
	rc.SetRect(this->m_pRect->left, this->m_pRect->top, this->m_pRect->right + LEN_PANELWIDTH + 16, this->m_pRect->bottom);
	if(!rc.PtInRect(point))
		return false;

	for(int i = 0; i < FMB_NUM; ++i)
	{
		if(m_TB[i].OnLButtonDblClk(nFlags, point))
			break;
	}

	return GraphicBase::OnLButtonDblClk(nFlags, point);
}

bool UI_EQPanel::OnRButtonDown(UINT nFlags, CPoint point)
{
	if(!this->m_pRect->PtInRect(point))
		return false;

	for(int i = 0; i < FMB_NUM; ++i)
	{
		if(m_TB[i].OnRButtonDown(nFlags, point))
			break;
	}

	return GraphicBase::OnRButtonDown(nFlags, point);
}

bool UI_EQPanel::OnRButtonUp(UINT nFlags, CPoint point)
{
	if(!this->m_pRect->PtInRect(point))
		return false;

	for(int i = 0; i < FMB_NUM; ++i)
	{
		if(m_TB[i].OnRButtonUp(nFlags, point))
			break;
	}

	return GraphicBase::OnRButtonUp(nFlags, point);
}
